<template>
  <div>
    <textarea :placeholder="tip1"
     v-model.trim="reportContent"/>
    
    <div class="divcls">
      <a class="butclass2" @click="commitAdvoice()">吐槽一下</a>
    </div>
  </div>

</template>

<script>
import card from '@/components/card'
import { requestPost } from '@/utils/index'
export default {
  data () {
    return {
      reportContent: '',
      userId: '-1',
      tip1: '这个商品不好,只能吐槽一次哦'
    }
  },
  onShow () {
    this.userId = this.$root.$mp.query.fromUserId
    if (mpvue.getStorageSync('co')) {
      this.tip1 = '对骚扰/欺诈/谩骂等违规行为申请一次吐槽,不可以刻意污蔑喔'
    }
  },
  onLoad () {},
  onUnload () {
    this.reportContent = ''
    // wx.clearStorageSync()
    // mpvue.removeStorageSync('token')
  },
  components: {
    card
  },
  methods: {
    commitAdvoice () {
      if (this.reportContent === '') {
        wx.showToast({
          title: '文本不能为空',
          icon: 'none',
          duration: 1500,
          mask: true
        })
        return
      }
      if (this.userId === '-1' || !mpvue.getStorageSync('co')) {
        this.reportContent = ''
        wx.showToast({
          title: '已提交吐槽',
          icon: 'success',
          duration: 2000,
          mask: true
        })
        return
      }
      var data = {
        'reportUserId': mpvue.getStorageSync('userId'),
        'beReportUserId': this.userId,
        'reportContent': this.reportContent,
        'token': mpvue.getStorageSync('token')
      }
      var that = this
      requestPost(mpvue.getStorageSync('requestUrl') + '/miniprogram/reportUser', data, 'POST').then(function (value) {
        console.log(value)
        if (value.code === 0) {
          that.reportContent = ''
          wx.showToast({
            title: '已提交吐槽',
            icon: 'success',
            duration: 2000,
            mask: true
          })
        } else {
          wx.showToast({
            title: value.message,
            icon: 'none',
            duration: 2000,
            mask: true
          })
        }
      }, function (value) {
        console.log(value)
      })
    }
  }
}
</script>

<style scoped>
textarea{
  border: 1px solid #FEF55A;
  margin: 20px auto;
  padding:8px;
  width: 90%;
  height: 210px;
  font-size: 23px;
}
.butclass2{
  width: 100%;
  height: 50px;
  line-height: 50px;
  font-size: 20px;
  text-align: center;
  color: rgb(14, 14, 22);
  background-color: #FEF55A;
  font-weight: bold;
}
.divcls{
  width: 100%;
  height: 50px;
  position: fixed;
  bottom: 0px;
}
</style>
